﻿using aier.dataaccess.dapper;
using aier.dataaccess.model;
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace aier.business.logic
{
    public class DepartmentBll
    {
        public DepartmentDal departmentDal { get; set; }

        public ILog log { get; set; }

        /// <summary>
        /// 根据名字查询科室id(QueryDepartmentIdByName)
        /// </summary>
        /// <param name="hospitalId"></param>
        /// <returns></returns>
        public IEnumerable<DepartmentView> GetDepartmentsByHospID(Guid hospitalId, string name)
        {

            try
            {
               return departmentDal.QueryDepartmentIdByName(hospitalId, name);

            }
            catch (Exception ex)
            {
                log.Error("GetDepartmentsByHospID: " + ex.Message);
                return null;
            }
     
        }

        /// <summary>
        /// 获取所有科室
        /// </summary>
        /// <returns></returns>
        public IEnumerable<DepartmentView> GetAll()
        {
         
            try
            {
                return departmentDal.GetAll();
            }
            catch (Exception ex)
            {
                log.Error("GetAll: " + ex.Message);

                return null;
            }
        }

        public IEnumerable<DepartmentView> GetDepartmentByHospitalId(Guid hospitalId)
        {
            if (hospitalId != Guid.Empty)
            {
                IEnumerable<DepartmentView> data = departmentDal.GetDepartmentByHospitalId(hospitalId);
                return data;
            }
            return null;
        }
    }
}
